<?php defined('LFNC_PACKAGE') or die('forbidden');


/**
* MLT Web Engine
* http://www.molotsoft.ru
*
* @package MLT_WE
* @subpackage Lucky_Funcs
* @author Ivan Chistyakov <ivan@molotsoft.ru>
* @version $Id: regexp.lfnc.php 277 2009-06-26 05:30:20Z molotsoft@gmail.com $
* @link $HeadURL: http://lucky-funcs.googlecode.com/svn/branches/version_1/funcs/regexp.lfnc.php $
*/


define('ID_PATTERN', '~^[0-9]{1,10}$~');
define('KEY_PATTERN', '~^[a-z0-9_]+$~i');
define('NAME_PATTERN', '~^[a-z0-9_\-]+$~i');
define('IDENT_PATTERN', '~^[_a-z][a-z0-9_]*$~i');

function id_match($id) {
	return (bool)preg_match(ID_PATTERN, $id);
}

function key_match($key) {
	return (bool)preg_match(KEY_PATTERN, $key);
}

function name_match($name) {
	return (bool)preg_match(NAME_PATTERN, $name);
}

function ident_match($ident) {
	return (bool)preg_match(IDENT_PATTERN, $ident);
}


define('DIGIT_PATTERN', '~^\d+$~');
define('SPACE_PATTERN', '~^\s+$~');
define('WORD_PATTERN', '~^\w+$~');

function digit_match($digit) {
	return (bool)preg_match(DIGIT_PATTERN, $digit);
}

function space_match($space) {
	return (bool)preg_match(SPACE_PATTERN, $space);
}

function word_match($word) {
	return (bool)preg_match(WORD_PATTERN, $word);
}


function mask2preg($pattern, $modifiers = 'i') {
	return '~^' . str_replace(array('\?', '\*'), array('.?', '.*'), preg_quote($pattern)) . '$~' . $modifiers;
}

function mask_match($pattern, $subject) {
	return (bool)preg_match(mask2preg($pattern), $subject);
}


define('URL_PATTERN', '~^(ftp|http|https)\://((?:[a-z0-9\-]+\.)+[a-z]{2,9})(/[^\s]*)?$~i'); // ???
define('EMAIL_PATTERN', '~^([a-z0-9_\-\+\.%]+)@((?:[a-z0-9\-]+\.)+[a-z]{2,9})$~i');
define('JABBER_PATTERN', '~^([a-z0-9_\-\+\.%]+)@((?:[a-z0-9\-]+\.)+[a-z]{2,9})$~i');
define('ICQ_PATTERN', '~^[0-9]{6,9}$~i');

function url_match($url) {
	return (bool)preg_match(URL_PATTERN, $url);
}

function email_match($email) {
	return (bool)preg_match(EMAIL_PATTERN, $email);
}

function jabber_match($jabber) {
	return (bool)preg_match(JABBER_PATTERN, $jabber);
}

function icq_match($icq) {
	return (bool)preg_match(ICQ_PATTERN, $icq);
}


?>